{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import os\n",
    "from tqdm import tqdm\n",
    "import lightgbm as lgb\n",
    "from sklearn.model_selection import StratifiedKFold\n",
    "from sklearn import metrics\n",
    "import warnings\n",
    "\n",
    "warnings.filterwarnings('ignore')\n",
    "train_path = '../input/hy_round1_train_20200102'\n",
    "test_path = '../input/hy_round1_testA_20200102'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7000 2000\n"
     ]
    }
   ],
   "source": [
    "train_files = os.listdir(train_path)\n",
    "test_files = os.listdir(test_path)\n",
    "print(len(train_files), len(test_files))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['6966.csv', '545.csv', '223.csv']"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_files[:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['8793.csv', '8787.csv', '8977.csv']"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_files[:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(f'{train_path}/6966.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>渔船ID</th>\n",
       "      <th>x</th>\n",
       "      <th>y</th>\n",
       "      <th>速度</th>\n",
       "      <th>方向</th>\n",
       "      <th>time</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>6966</td>\n",
       "      <td>6.265902e+06</td>\n",
       "      <td>5.279254e+06</td>\n",
       "      <td>0.11</td>\n",
       "      <td>306</td>\n",
       "      <td>1106 23:58:16</td>\n",
       "      <td>围网</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>6966</td>\n",
       "      <td>6.265902e+06</td>\n",
       "      <td>5.279254e+06</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0</td>\n",
       "      <td>1106 23:48:21</td>\n",
       "      <td>围网</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>6966</td>\n",
       "      <td>6.265902e+06</td>\n",
       "      <td>5.279254e+06</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0</td>\n",
       "      <td>1106 23:38:19</td>\n",
       "      <td>围网</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>6966</td>\n",
       "      <td>6.265902e+06</td>\n",
       "      <td>5.279254e+06</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0</td>\n",
       "      <td>1106 23:28:36</td>\n",
       "      <td>围网</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>6966</td>\n",
       "      <td>6.265902e+06</td>\n",
       "      <td>5.279254e+06</td>\n",
       "      <td>0.32</td>\n",
       "      <td>130</td>\n",
       "      <td>1106 23:08:17</td>\n",
       "      <td>围网</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   渔船ID             x             y    速度   方向           time type\n",
       "0  6966  6.265902e+06  5.279254e+06  0.11  306  1106 23:58:16   围网\n",
       "1  6966  6.265902e+06  5.279254e+06  0.00    0  1106 23:48:21   围网\n",
       "2  6966  6.265902e+06  5.279254e+06  0.00    0  1106 23:38:19   围网\n",
       "3  6966  6.265902e+06  5.279254e+06  0.00    0  1106 23:28:36   围网\n",
       "4  6966  6.265902e+06  5.279254e+06  0.32  130  1106 23:08:17   围网"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['围网'], dtype=object)"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['type'].unique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(389, 7)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 7000/7000 [00:34<00:00, 260.00it/s]\n"
     ]
    }
   ],
   "source": [
    "ret = []\n",
    "for file in tqdm(train_files):\n",
    "    df = pd.read_csv(f'{train_path}/{file}')\n",
    "    ret.append(df)\n",
    "df = pd.concat(ret)\n",
    "df.columns = ['ship','x','y','v','d','time','type']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.to_hdf('../input/train.h5', 'df', mode='w')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 2000/2000 [00:08<00:00, 225.65it/s]\n"
     ]
    }
   ],
   "source": [
    "ret = []\n",
    "for file in tqdm(test_files):\n",
    "    df = pd.read_csv(f'{test_path}/{file}')\n",
    "    ret.append(df)\n",
    "df = pd.concat(ret)\n",
    "df.columns = ['ship','x','y','v','d','time']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.to_hdf('../input/test.h5', 'df', mode='w')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(782378, 6)"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>渔船ID</th>\n",
       "      <th>x</th>\n",
       "      <th>y</th>\n",
       "      <th>速度</th>\n",
       "      <th>方向</th>\n",
       "      <th>time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>8793</td>\n",
       "      <td>6.102450e+06</td>\n",
       "      <td>5.112760e+06</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0</td>\n",
       "      <td>1106 23:56:34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>8793</td>\n",
       "      <td>6.102450e+06</td>\n",
       "      <td>5.112760e+06</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0</td>\n",
       "      <td>1106 23:46:34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>8793</td>\n",
       "      <td>6.102450e+06</td>\n",
       "      <td>5.112760e+06</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0</td>\n",
       "      <td>1106 23:37:31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>8793</td>\n",
       "      <td>6.102450e+06</td>\n",
       "      <td>5.112760e+06</td>\n",
       "      <td>0.16</td>\n",
       "      <td>0</td>\n",
       "      <td>1106 23:26:34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>8793</td>\n",
       "      <td>6.102450e+06</td>\n",
       "      <td>5.112760e+06</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0</td>\n",
       "      <td>1106 23:16:34</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   渔船ID             x             y    速度  方向           time\n",
       "0  8793  6.102450e+06  5.112760e+06  0.00   0  1106 23:56:34\n",
       "1  8793  6.102450e+06  5.112760e+06  0.00   0  1106 23:46:34\n",
       "2  8793  6.102450e+06  5.112760e+06  0.00   0  1106 23:37:31\n",
       "3  8793  6.102450e+06  5.112760e+06  0.16   0  1106 23:26:34\n",
       "4  8793  6.102450e+06  5.112760e+06  0.00   0  1106 23:16:34"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
